/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
    el: "#main",
    data: {
        selectList: [],
        systemCode: "", //系统编码
        systemName: "", //系统名称
        projectList: [], //产品列表
        productCode: "",
        tipCode: "",
        tipCodeList: [],
        tipVersionList: [],
    },
    created: function() {
        const _this = this;
        _this.queryselect();
    },
    methods: {
        //修改进入初始化
        modinit: function() {
            $("#mod").css("display", "");
            _data = {};
            url = location.search.split("=");
            _data.id = url[1];
            App.ajax({
                type: "POST",
                url: App.getApiUrl("modfriend"),
                data: _data,
                success: function(data) {
                    $("#friend_no").val(data.OPT_NO);
                    $("#friend_name").val(data.OPT_NAME);
                    $("#mod_optid").val(data.OPT_ID);
                    $("#mod_id").val(data.id);
                    if (data.companyType == 1) {
                        $("#leixing .am-fl").text("保险");
                        $("#lei").val(data.companyType);
                    }
                    if (data.OPT_STATUS == 1) {
                        $("#stats .am-fl").text("有效");
                        $("#sta").val(data.OPT_STATUS);
                    } else {
                        $("#stats .am-fl").text("无效");
                        $("#sta").val(data.OPT_STATUS);
                    }
                    $("#beginDay").val(data.applicationDate);
                    $("#phone").val(data.phone);
                    $("#email").val(data.email);
                },
            });
        },
        //新增方法
        submit: function() {
            const _this = this;
            let obj = {
                systemCode: _this.systemCode, //系统编码
                systemName: _this.systemName, // 系统名称
                tipId: _this.tipid, // 提示信息id
                switchFlag: '0', //开关
            };
            axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"tipMatch/matchSave",
                    data: obj,
                })
                .then((data) => {
                    console.log(data.data);
                    if (data.data.code === "200") {
                        window.location.href = "proSearch.html";
                        // _this.selectList = data.data.data;
                        // this.nowPage = data.data.data[0].nowPage;
                        // this.allPages = data.data.data[0].allPage;
                        // this.pagination = getPagination(this.nowPage, this.allPages);
                    } else {
                        parent.showAlert(data.data.msg);
                    }
                })
                .catch((err) => {});
        },
        // 获取系统
        queryselect: function() {
            const _this = this;
            let obj = {};
            axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"tipMatch/querySysteam",
                    data: obj,
                })
                .then((data) => {
                    console.log(data.data);
                    if (data.data.code === "200") {
                        _this.selectList = data.data.data;

                        // this.nowPage = data.data.data[0].nowPage;
                        // this.allPages = data.data.data[0].allPage;
                        // this.pagination = getPagination(this.nowPage, this.allPages);
                    } else {
                        parent.showAlert(data.data.msg);
                    }
                })
                .catch((err) => {});
        },
        //系统选择
        getvaluemethod: function(event) {
            //获取当前选中的值，并重新赋值
            const _this = this;
            _this.projectList = [];
            _this.tipCodeList = [];
            _this.tipVersionList = [];
            var values = event.target.value;
            console.log(values);
            console.log(isNaN(values));

            if (values.length > 0) {
                _this.systemCode = _this.selectList[values].sysCode;
                _this.systemName = _this.selectList[values].sysName;
                console.log(_this.selectList);
                this.queryList("1");
            }
        },
        // 产品选择
        changeProject: function(event) {
            //获取当前选中的值，并重新赋值
            const _this = this;
            _this.tipCodeList = [];
            _this.tipVersionList = [];
            var values = event.target.value;
            if (values.length > 0) {
                _this.productCode = _this.projectList[values].productCode;
                console.log(values)
                console.log(_this.selectList)
                console.log(_this.productCode);
                this.queryList("2");
            }
        },
        // 提示编码
        changeTipCode: function(event) {
            //获取当前选中的值，并重新赋值
            const _this = this;
            _this.tipVersionList = [];
            var values = event.target.value;
            if (values.length > 0) {
                _this.tipCode = _this.tipCodeList[values].tipCode;
                this.queryList("3");
            }
        },
        // 提示版本号
        changeTipVersion: function(event) {
            //获取当前选中的值，并重新赋值
            const _this = this;
            var values = event.target.value;
            if (values.length > 0) {
                _this.tipVersion = _this.tipVersionList[values].tipVersion;
                _this.tipid = _this.tipVersionList[values].tipid;
                // tipid
            }
        },
        queryList(flag) {
            const _this = this;
            let obj = {
                systemCode: _this.systemCode,
                systemName: _this.systemName,
                flag: flag, // 步骤 1 2 3
                productCode: _this.productCode, //产品编码
                tipCode: _this.tipCode, //提示编码
            };
            axios({
                    method: "post",
                    url: App.envUrl.backtrackUrl+"tipMatch/queryMatchList",
                    data: obj,
                })
                .then((data) => {
                    if (data.data.code === "200") {
                        if (flag == 1) {
                            //查询产品列表
                            _this.projectList = data.data.data;

                        } else if (flag == 2) {
                            _this.tipCodeList = data.data.data;
                            console.log(_this.tipCodeList)
                        } else if (flag == 3) {
                            _this.tipVersionList = data.data.data;
                        }
                    } else {
                        parent.showAlert(data.data.msg);
                    }
                })
                .catch((err) => {});
        },

        friend_return: function() {
            window.location.href = "proSearch.html";
        },
    },
});

function getvaluemethod(event) {
    vm.getvaluemethod(event);
}

function changeProject(event) {
    vm.changeProject(event);
}

function changeTipCode(event) {
    vm.changeTipCode(event);
}

function changeTipVersion(event) {
    vm.changeTipVersion(event);
}